/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sistemperpustakaan.actionlistener;



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.JInternalFrame;
import sistemperpustakaan.view.FrmMain;
import sistemperpustakaan.view.buku.FrmBukuView;

/**
 *
 * @author Eko Aprianto
 */
public class ViewBukuActionListener implements ActionListener{
    FrmMain main;

    public ViewBukuActionListener(FrmMain main) {
        this.main = main;
    }

    public boolean isExists(){
        boolean result = false;
        JInternalFrame[] iFrame = main.getDesktopPane().getAllFrames();
        for(int i=0;i < iFrame.length; i++){
            if(iFrame[i].equals(main.getBukuView())){
                result = true; break;
            }
        }
        return result;
    }

    public void actionPerformed(ActionEvent e) {
        if(isExists()){
            try {
                main.getBukuView().setSelected(true);
            } catch (PropertyVetoException ex) {
            }
         }else{
            main.setBukuView(new FrmBukuView(main));
            main.getDesktopPane().add(main.getBukuView());
            try { main.getBukuView().setMaximum(true); } catch (PropertyVetoException ex) {  } 
            main.getBukuView().setVisible(true);
         }
    }
}
